package com.one.efaimaly.order.presenter;

import android.view.View;
import android.widget.TextView;

import com.one.common.config.OrderState;
import com.one.common.utils.StringUtils;
import com.one.efaimaly.R;
import com.one.efaimaly.main.model.item.OrderItem;
import com.one.efaimaly.order.model.item.OrderDetailItem;

/**
 * creator: zhulunjun
 * time:    2018/8/9
 * describe:
 */
public class OrderStateHandle {

    /**
     * 各状态下按钮的显示
     */
    public static void setStateView(OrderItem item, TextView btn1, TextView btn2, TextView btn3) {

        String state = item.getOrder_state();
        if (StringUtils.isBlank(state)) {
            state = OrderState.WAIT_VISIT;
        }
        switch (state) {
            case OrderState.WAIT_VISIT: // 待上门
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText(StringUtils.format(R.string.state_confirm));
                btn1.setText(StringUtils.format(R.string.state_cancel));
                break;
            case OrderState.WAIT_CONFIRM: // 等待确认服务
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText(StringUtils.format(R.string.state_update));
                btn1.setText(StringUtils.format(R.string.state_cancel));
                break;
            case OrderState.WAIT_PAY: // 待付款
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.GONE);
                btn1.setVisibility(View.GONE);
                break;
            case OrderState.PAY_END:  // 已付款
                // 已完成状态分两种情况
                // 1. 有维修图片，显示查看图片
                // 2. 无维修图片，显示上传图片
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.GONE);
                if (StringUtils.isBlank(item.getOrder_maintail_imgs1()) && StringUtils.isBlank(item.getOrder_maintail_imgs2())) {
                    btn1.setText(StringUtils.format(R.string.state_upload_img));
                } else {
                    btn1.setText(StringUtils.format(R.string.state_show_img));
                }
                break;
            case OrderState.CANCEL:
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.GONE);
                btn1.setText(StringUtils.format(R.string.state_cancel));
                break;
            default:
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText(StringUtils.format(R.string.state_confirm));
                btn1.setText(StringUtils.format(R.string.state_cancel));
                break;
        }
    }

    public static String getStateStr(String state) {
        String result;
        if (StringUtils.isBlank(state)) {
            state = OrderState.WAIT_VISIT;
        }
        switch (state) {
            case OrderState.WAIT_VISIT:
                result = "待上门";
                break;
            case OrderState.WAIT_CONFIRM:
                result = "待确认";
                break;
            case OrderState.WAIT_PAY:
                result = "待付款";
                break;
            case OrderState.PAY_END:
                result = "已完成";
                break;
            case OrderState.CANCEL:
                result = "已关闭";
                break;
            default:
                result = "待上门";
                break;
        }
        return result;
    }
}
